package org.sunshine.miracle.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class MainShellMenu {

    private Shell shell;
    private Menu parentMenu;

    public MainShellMenu(Shell parenShell) {
        this.shell = parenShell;
        parentMenu = SWTUtils.createMenu(shell, SWT.BAR);
        createFileMenu();
        createHelpMenu();
    }

    private void createFileMenu() {
        shell.setMenuBar(parentMenu);

        Menu menu = SWTUtils.createMenu(parentMenu);
        MenuItem header = SWTUtils.createMenuItem(parentMenu, SWT.CASCADE);
        header.setText(StringBundle.getResourceString("menu.File.text"));
        header.setMenu(menu);

        MenuItem item = new MenuItem(menu, SWT.PUSH);
        item.setText(StringBundle.getResourceString("menu.File.adddir.text"));
        item.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
//                addRoot();
            }
        });


        item = new MenuItem(menu, SWT.PUSH);
        item.setText(StringBundle.getResourceString("menu.File.Close.text"));
        item.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                shell.close();
            }
        });
    }


    /** Creates the Help Menu. */
    private void createHelpMenu() {
        Menu menu = new Menu(parentMenu);
        MenuItem header = new MenuItem(parentMenu, SWT.CASCADE);
        header.setText(StringBundle.getResourceString("menu.Help.text"));
        header.setMenu(menu);

        MenuItem item = new MenuItem(menu, SWT.PUSH);
        item.setText(StringBundle.getResourceString("menu.Help.About.text"));
        item.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                box.setMessage(StringBundle.getResourceString("dialog.About.description", new Object[]{System.getProperty("os.name")}));
                box.setText(StringBundle.getResourceString("dialog.About.title"));
                box.open();
            }
        });
    }


}
